Page({
  data: {
    active: 'home',
    activeName: '1',
    loved: [false, false, false, false, false, false, false, false, false, false],
    userInfo: {},
    hasUserInfo: false,
    //canIUse: wx.canIUse('button.open-type.getUserInfo'),
    canIUseGetUserProfile: false,
    //canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
  },
  onChangePage(event) { //切换底部导航项目
    // event.detail 的值为当前选中项的索引
    this.setData({
      active: event.detail
    });
  },
  onChange(event) { //切换折叠面板
    this.setData({
      activeName: event.detail,
    });
  },
  loved(event) { //收藏爱心功能
    let goal = event.target.id;
    const detail = event.detail;
    if (goal == "loved1") {
      this.setData({
        'loved[1]': detail
      })
    } else if (goal == "loved2") {
      this.setData({
        'loved[2]': detail
      })
    } else if (goal == "loved3") {
      this.setData({
        'loved[3]': detail
      })
    } else if (goal == "loved4") {
      this.setData({
        'loved[4]': detail
      })
    } else if (goal == "loved5") {
      this.setData({
        'loved[5]': detail
      })
    } else if (goal == "loved6") {
      this.setData({
        'loved[6]': detail
      })
    } else if (goal == "loved7") {
      this.setData({
        'loved[7]': detail
      })
    } else if (goal == "loved8") {
      this.setData({
        'loved[8]': detail
      })
    } else if (goal == "loved9") {
      this.setData({
        'loved[9]': detail
      })
    }
  },
  handleClick(event) { //跳转按钮功能
    let goal = event.target.id;
    if (goal == "jez") {
      wx.navigateTo({
        url: '/pages/jez/jez',
      })
    } else if (goal == "bmi") {
      wx.navigateTo({
        url: '/pages/bmi/bmi',
      })
    } else if (goal == "saol") {
      wx.navigateTo({
        url: '/pages/saol/saol',
      })
    } else if (goal == "szhb") {
      wx.navigateTo({
        url: '/pages/szhb/szhb',
      })
    } else if (goal == "jsq") {
      wx.navigateTo({
        url: '/pages/jsq/jsq',
      })
    } else if (goal == "zd") {
      wx.navigateTo({
        url: '/pages/zd/zd',
      })
    } else if (goal == "ewms") {
      wx.navigateTo({
        url: '/pages/ewms/ewms',
      })
    } else if (goal == "cand") {
      wx.navigateTo({
        url: '/pages/cand/cand',
      })
    } else if (goal == "weather") {
      wx.navigateTo({
        url: '/pages/weather/weather',
      })
    }
  },
  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
  getUserInfo(e) {
    // 不推荐使用getUserInfo获取用户信息，预计自2021年4月13日起，getUserInfo将不再弹出弹窗，并直接返回匿名的用户个人信息
    console.log(e)
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
});